﻿using System;
using System.Collections.Generic;
using Color = System.Drawing.Color;
using SwinGame;

namespace Gundam_2._0_Alpha.src
{
    public class Projectile:DestroyableObject
    {
        private bool isActive = true;
        private Vector v;
        private Character c;

        public Vector V
        {
            get { return v; }
            set { v = value; }
        }

        public bool IsActive
        {
            get { return isActive; }
            set { isActive = value; }
        }

        public Projectile(string name, int health, Sprite objectSprite, Character c)
            : base(name, health, objectSprite)
        {
            this.c = c;
        }

        public override void  Update(GameController gc)
        {
            if (!isActive) return;

            objectSprite.X += v.x;
            objectSprite.Y += v.y;

            if (objectSprite.IsOffscreen() || health <= 0)
                Reset(gc);

            GlobalConst.DmgCheck.CheckDamage(gc.GameStages.Peek().CharList, objectSprite, true, 200, gc, true, 0.05f);
        }

        public override void Draw()
        {
            if (isActive)
                objectSprite.Draw();
        }

        public void Reset(GameController gc)
        {
            this.isActive = false;
            objectSprite.X = Geometry.CenterPoint(c.ObjectSprite).x - c.ShootOffsetX(); 
            objectSprite.Y = Geometry.CenterPoint(c.ObjectSprite).y - c.ShootOffsetY;
            gc.GameStages.Peek().ToDelete.Add(this);
            health = maxHealth;
        }
    }
}
